<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
       
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            不合格条码重置
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">

        <div id="citemList" class="aui-content">

            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">产品条码</div>
                        <div class="aui-list-item-input">
                            <input id="barcode"></input>
                        </div>
                    </div>
                </li>


            </ul>

        </div>

        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr
                    style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center'>序号</td>
                        <td algin='center'>产品条码</td>
                        <td algin='center'>工序</td>
                        <td algin='center'>工位</td>
                        <td algin='center'>状态</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>

    </div>
    <div class='aui-btn aui-btn-info' style='width:40%;margin-top: 30%;margin-left:7%' onclick='doSaveHg()'>合格</div>
    <div class='aui-btn aui-btn-info' style='width:40%;margin-top: 30%;margin-left:6%' onclick='doSaveBhg()'>不合格</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript">



    var sysid = '';
    //初始化
    apiready = function () {

        $("#barcode").focus();

    };


    function doSaveHg() {
        api.confirm({
            title: '提示',
            msg: "是否将该条码状态改为合格？",
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                api.showProgress({
                    title: '保存中...',
                });
                var un = localStorage.getItem('un');
                var serverUrl = localStorage.getItem('serverUrl');
                var url = serverUrl + "/app/saveProduct";
                var params = new Object();
                params.url = url;
                params.dataType = 'json';
                params.method = 'post';
                var data = {
                    values: { ////以表单方式提交参数（JSON对象）
                        sysid: sysid,
                        flag:'合格',
                        un: un
                    }
                };
                api.ajax({
                    url: url,
                    method: 'post',
                    dataType: 'json',
                    timeout: 30,
                    returnAll: false,
                    data: data
                }, function (ret, err) {
                    if (ret) {

                        var data = JSON.stringify(ret);
                        var myobj = eval("(" + data + ")");
                        //成功
                        if (myobj.code == '0') {

                            api.hideProgress();
                            doSearch()
                            api.toast({
                                msg: "保存成功",
                                duration: 3000
                            });
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: myobj.msg,
                                duration: 3000
                            });
                        }
                    }
                });
            }
        }
        )


    }

    function doSaveBhg() {
        api.confirm({
            title: '提示',
            msg: "是否将该条码状态改为不合格？",
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                api.showProgress({
                    title: '保存中...',
                });
                var un = localStorage.getItem('un');
                var serverUrl = localStorage.getItem('serverUrl');
                var url = serverUrl + "/app/saveProduct";
                var params = new Object();
                params.url = url;
                params.dataType = 'json';
                params.method = 'post';
                var data = {
                    values: { ////以表单方式提交参数（JSON对象）
                        sysid: sysid,
                        flag:'不合格',
                        un: un
                    }
                };
                api.ajax({
                    url: url,
                    method: 'post',
                    dataType: 'json',
                    timeout: 30,
                    returnAll: false,
                    data: data
                }, function (ret, err) {
                    if (ret) {

                        var data = JSON.stringify(ret);
                        var myobj = eval("(" + data + ")");
                        //成功
                        if (myobj.code == '0') {

                            api.hideProgress();
                            doSearch()

                            api.toast({
                                msg: "保存成功",
                                duration: 3000
                            });
                        } else {
                            api.hideProgress();
                            api.toast({
                                msg: myobj.msg,
                                duration: 3000
                            });
                        }
                    }
                });
            }
        }
        )


    }


    //产品条码监听回车事件
    $("#barcode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            doSearch()
        }
    });

    //查询
    function doSearch() {
        var produBarcode = $("#barcode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/selectProduct";
        var data = {
            values: {
                produBarcode: produBarcode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        html += "<td name='seqno'>" + (i + 1) + "</td>";
                        html += "<td name='produBarcode'>" + list[i].produBarcode + "</td>";
                        html += "<td name='opCode'>" + list[i].opCode + "</td>";
                        html += "<td name='workCellCode'>" + list[i].workCellCode + "</td>";
                        html += "<td name='checkFlag'>" + list[i].checkFlag + "</td>";
                        html += "</tr>";
                        sysid = list[i].sysid
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {
                    $("#barcode").val("")
                    sysid='';

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }


   


    //返回按钮
    function closeWin() {
        // 
        if (api.pageParam.barcode == undefined) {
            api.closeWin({});
        } else {
            api.closeToWin({ name: api.pageParam.name });
            api.execScript({
                name: api.pageParam.name,
                script: 'refreshData()'
            });
        }
    }


</script>

</html>